package com.yzycoc.coc.gf.util;

import java.util.regex.Pattern;

/**
 * module-sdk-coc
 *
 * @author Administrator
 * @since 2023/9/7 22:35
 **/
public class CocUtil {

    public static Boolean contains(String msg, String s) {
        String[] split = s.split(",");
        for (String val : split) {
            if (msg.contains(val)) return true;
        }
        return false;
    }


    public static Boolean equals(String msg, String s) {
        String[] split = s.split(",");
        for (String val : split) {
            if (msg.equals(val)) return true;
        }
        return false;
    }


    public static boolean containsSpecialChars(String str) {
        // 定义特殊字符的正则表达式
        String specialCharsRegex = "[!@#$%^&*(),.?\":{}|<>]";
        // 判断字符串是否匹配特殊字符的正则表达式
        return Pattern.compile(specialCharsRegex).matcher(str).find();
    }

    public static Boolean isTag(String tag) {
        if (tag == null || tag.length() <= 3) {
            return false;
        }
        if (!"#".equals(tag.substring(0, 1))) {
            return false;
        }
        tag = tag.replace("#", "");
        int length = tag.length();
        if (length >= 3 && length <= 14) {
            String regex = "^[a-z0-9A-Z]+$";
            return tag.matches(regex);
        }
        return false;
    }

    public static String analysis(String msg, String defaultStr) {
        String[] split = defaultStr.split(",");
        for (String str : split) {
            if (msg.length() < str.length()) {
                continue;
            }
            if (str.equals(msg.substring(0, str.length()))) {
                return str;
            }
        }
        return null;
    }
}
